package univer.oko;

import univer.oko.utilities.CDUtilities;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;


/**
 * @author Dudar Eduard
 */
public class About extends JDialog {
    protected class AccessMouseListener extends MouseAdapter {
        public void mouseClicked(MouseEvent me) {
            dispose();
        }
    }

    private class ImagePane extends JPanel {
        public ImagePane() {
            super();
            this.setPreferredSize(new Dimension(438, 140));
            this.addMouseListener(new About.AccessMouseListener());
        }

        public void paint(Graphics g) {
            g.drawImage(CDUtilities.createIcon("5.jpg").getImage(), 0, 0, this);

            g.setColor(Color.DARK_GRAY);
            g.setFont(new Font("Arial", Font.BOLD, 12));
            g.drawString("V.N. Karazin", 5, 13);
            g.drawString("Kharkiv National University", 5, 27);
            g.setFont(new Font("Arial", Font.PLAIN, 12));
            g.drawString("CTC \u00A9 2005", 367, 13);
        }
    }

    public About(MainFrame mainFrame) {
        super(mainFrame, true);
        this.getContentPane().setLayout(new BorderLayout());
        ((JPanel) this.getContentPane()).setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY));

        this.initImagePane();
        this.initAccountPane();

        this.setUndecorated(true);
        this.setResizable(false);
        this.pack();
        CDUtilities.centreWindow(this);
    }

    public void initImagePane() {
        this.getContentPane().add(new About.ImagePane(), BorderLayout.CENTER);
    }

    public void initAccountPane() {
        JPanel accountPane = new JPanel();
        accountPane.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));

        GridBagLayout layout = new GridBagLayout();
        accountPane.setLayout(layout);

        GridBagConstraints constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridwidth = 3;
        constraints.gridheight = 1;
        constraints.weightx = 10;
        constraints.weighty = 10;
        constraints.insets = new Insets(3, 3, 3, 3);

        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.CENTER;

        accountPane.setPreferredSize(new Dimension(0, 120));

        this.getContentPane().add(accountPane, BorderLayout.SOUTH);
    }
}